package com.fengye.algorithms.huawei;

import java.util.Scanner;

/**
 * https://www.nowcoder.com/practice/4b1658fd8ffb4217bc3b7e85a38cfaf2?tpId=37&tqId=21309&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
 * @Author fengye
 * @Date 2023/4/7 11:19
 **/
public class ContinueBit1NumMain {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            String str = Integer.toBinaryString(a);
            System.out.println(fun(str));
        }
    }

    public static int fun(String str) {
        int length = str.length();
        int result = 1;

        StringBuilder sb = new StringBuilder();
        // 一样长的1初始化
        for (int i = 0; i < length; i++) {
            sb.append("1");
        }

        String temp = sb.toString();
        for (int i = 0; i < length; i++) {
            if (str.contains(temp)) {
                return temp.length();
            }
            // 每次减一看看
            temp = temp.substring(1);
        }

        return result;
    }
}
